
<template>
  <search-table
    :data="testVulnerabilityList"
    :columns="testVulnerabilityCol"
    :page.sync="queryParams.pageIndex"
    :size.sync="queryParams.pageSize"
    :total="testVulnerabilityTotal"
    :loading="testVulnerabilityListLoading"
    @queryFun="getList">
    <template slot="search">
      <Select filterable clearable v-model="queryParams.level" @on-change="selectLevel" placeholder="选择漏洞级别" style="margin-left: 15px;width: 150px">
        <Option value="0">超危</Option>
        <Option value="1">高危</Option>
        <Option value="2">中危</Option>
        <Option value="3">低危</Option>
      </Select>
      <Select filterable clearable v-model="queryParams.businessSystemId" @on-change="selectSystem" placeholder="选择业务系统" style="margin-left: 15px;width: 150px">
        <Option v-for="system in businessSystemList" :key="system.id" :value="system.id">{{system.targetName}}</Option>
      </Select>
      <Input v-model.trim="queryParams.vulName"  clearable placeholder="输入漏洞名称" @on-change="searchVulnerabilityName" style="width: 180px;margin-left: 15px" />
    </template>
    <VulnerabilityDetail
        ref="VulnerabilityDetail"></VulnerabilityDetail>
    <Modal
        v-model="showHistoryModal"
        title="漏洞日志"
        footer-hide
        class="my-modal"
    >
      <HistoryPage
          :isBug="false"
          ref="historyPage"
      >
      </HistoryPage>
    </Modal>
  </search-table>
</template>

<script>
import {queryExtraTestVulList} from '../api/extraTest'

import { validateIp, validatePort, validateUrlShort1 } from '@/libs/reg'
import HistoryPage from "../../vulnerability/detail/history-page.vue";
import {vulnerabilityStatusEscape,vulnerabilityLevelEscape} from '../../vulnerability/logic/vulnerabilityLogic'
import {getSystemList, getSystemList1} from "../logic/assetLogic";
import VulnerabilityDetail from "../../vulnerability/detail/vulnerability-detail.vue";
export default {
  name: 'PartManage',

  components: {
    VulnerabilityDetail,
    HistoryPage

  },
  props: {
    testActivityId: {
      type: String,
      default: ''
    }
  },
  computed: {
  },
  data() {
    return {
      queryParams:{
        pageIndex:1,
        pageSize:10
      },
      businessSystemList:[],
      testVulnerabilityList:[],
      testVulnerabilityListLoading:false,
      showHistoryModal:false,
      testVulnerabilityTotal:0,
      upgradeType: 'add',
      isUpgrade: false,
      detailModalData: {
        show: false
      },
      detailInfo: {},
      testVulnerabilityCol: [
        {
          title:'漏洞名称',
          key:'name',
        },
        {
          title:'严重级别',
          key:'level',
          render: (h, params) => {
            let ret = vulnerabilityLevelEscape(params.row.level)
            return h('Tag', {
              props: {
                color: ret.color
              },
              style: {
                width: '70px',
                'text-align': 'center'
              }
            }, ret.text)
          }
        },
        {
          title:'漏洞状态',
          key:'status',
          render: (h, params) => {
            let ret = vulnerabilityStatusEscape(params.row.status)
            return h('Tag', {
              props: {
                color: ret.color
              },
              style: {
                width: '70px',
                'text-align': 'center'
              }
            }, ret.text)
          }
        },
        {
          title:'威胁评分',
          key:'value'
        },
        {
          title:'业务系统名称',
          key:'targetName',
        },
        {
          title:'业务系统所属单位',
          key:'companyName'
        },
        {
          title: '操作',
          slot: 'action',
          width: 230,
          opList: [
            {

              txt: '详情',
              on:{
                click:(data,e) => {
                  this.showDetail(data)

                }
              },
            },
            {
              txt: '日志',
              on:{
                click:(data,e) => {
                  this.showHistory(data)
                }
              },
            }
          ]
        }
      ],
      modalData: {
        show: false,
        loading: false
      },
      currentTestActivityId:'',
      institutionList:[],
      industryList:[],
      netMeshList:[],
      netInfoList:[],
    }
  },
  methods: {
    init(id){
      this.queryParams = {
        pageIndex: 1,
        pageSize: 10
      }
      this.businessSystemList = []
      this.queryList(id)
    },
    getList(){
      this.queryList(this.currentTestActivityId)
    },
    getSearchSystemList(id){
      getSystemList1(this,'businessSystemList',id)
    },
    selectLevel(){
      this.queryParams.pageIndex = 1;
      this.getList();
    },
    searchVulnerabilityName(){
      this.queryParams.pageIndex = 1;
      this.getList();
    },
    selectSystem(){
      this.queryParams.pageIndex = 1;
      this.getList();
    },
    showDetail(data){
      this.$refs.VulnerabilityDetail.getVulnerabilityDetail(data.id)
    },
    showHistory(data){
      this.showHistoryModal = true;
      this.$refs.historyPage.getBugLogOrVulnerabilityLogList(data);
    },
    queryList(testActivityId){
      this.testVulnerabilityListLoading = true;
      this.currentTestActivityId = testActivityId;
      let passParams = {
        id: testActivityId,
        //id:'EXT44b16-582d-45c1-9b86-fd22d2ca83ba',
        ...this.queryParams
      }
      queryExtraTestVulList(passParams).then(res=>{
        if(res.code==1){
          this.testVulnerabilityList = res.data.items;
          this.testVulnerabilityTotal = res.data.total;
        }else{
          this.$Message.error(res.message);
        }
      }).finally(()=>{
        this.testVulnerabilityListLoading = false;
      })
    },
  }
}
</script>

